//package com.eneat.smartrule.Controller;
//
//import com.eneat.smartrule.Model.*;
//import com.eneat.smartrule.RestAPI.AbstractController;
//import com.eneat.smartrule.RestAPI.HttpResult;
//import com.eneat.smartrule.enums.ArithmeticOperatorEnum;
//import com.eneat.smartrule.enums.LogicEnum;
//import com.eneat.smartrule.enums.ComparisonOperatorEnum;
//import com.eneat.smartrule.Model.ArithmeticExpression;
//import com.eneat.smartrule.util.ExpressionUtil;
//import com.googlecode.aviator.AviatorEvaluator;
//import com.googlecode.aviator.Expression;
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.*;
//
//@RestController
//@RequestMapping(path = "/v1/")
//@Tag(name = "规则引擎相关接口")
//@Slf4j
//@CrossOrigin
//public class ExpressionController  extends AbstractController {
//    @Operation(summary = "测试")
//    @GetMapping(path = "/test")
//    public HttpResult<String> test() {
//        String expression = "a=='河北省'&&((b=='男人'||c>=30)||d=='黄')";
//         expression = "a*b";
//
//        // 编译表达式
//        Expression compiledExp = AviatorEvaluator.compile(expression);
//
//        Map<String, Object> env = new HashMap<>();
//        env.put("a", 80);
//        env.put("b", 70);
////        env.put("c",1);
////        env.put("d","黄");
////
//
//        // 执行表达式，可以返回满不满足，true或者false，也可以计算值。
//        System.out.println( compiledExp.execute(env));
//
//
//        return new HttpResult<>("success", true, 200, "success");
//
//    }
//    @Operation(summary = "测试")
//    @PutMapping ()
//    public HttpResult<String> add(@RequestBody Rule rule) {
//
//        return new HttpResult<>("success", true, 200, "success");
//    }
//
//    public static void main(String[] args) {
//        Rule rule = new Rule();
//        List<ArithmeticExpression> expr1 = List.of(new ArithmeticExpression("A"),
//                new ArithmeticExpression(ArithmeticOperatorEnum.SUBTRACT,"B") );
//        RuleCondition ruleCondition1 = new RuleCondition();
//        ruleCondition1
//                .setArithmeticExpressions(expr1)
//                .setOperator(ComparisonOperatorEnum.GT)
//                .setFieddValue(List.of("5"))
//                .setLogic(LogicEnum.AND)
//                .setBracketed(false);
//
//        List<ArithmeticExpression> expr2 = List.of(new ArithmeticExpression(  "B"));
//        RuleCondition ruleCondition2 = new RuleCondition();
//        ruleCondition2.setArithmeticExpressions(expr2)
//                .setOperator(ComparisonOperatorEnum.LT)
//                .setValue(List.of("哈哈和"))
//                .setIsValueQuoted(false)
//                .setLogic(LogicEnum.OR)
//                .setBracketed(false);
//
//        RuleCondition ruleCondition3 = new RuleCondition();
//        ruleCondition3.setArithmeticExpressions(List.of(new ArithmeticExpression("C")))
//                .setOperator(ComparisonOperatorEnum.EQ)
//                .setValue(List.of("哈哈"))
//                .setLogic(LogicEnum.OR)
//                .setIsValueQuoted(true)
//                .setBracketed(false);
//
//       List<RuleCondition> orRuleConditions = Arrays.asList(ruleCondition2, ruleCondition3);
//       RuleCondition combinedcondition = new RuleCondition();
//       combinedcondition.setSubRuleConditions(orRuleConditions)
//               .setBracketed(true);
//
//        List<RuleCondition> inputRuleConditions = Arrays.asList(ruleCondition1, combinedcondition);
//
//        rule.setRuleConditions(inputRuleConditions);
//
//         //Rule rule = new Rule( "rule1","", inputRuleConditions, ruleAction1, callbackRuleAction1);
//        Map<String, Object> env = new HashMap<>();
//        env.put("A", 60);
//        env.put("B", null);
//        env.put("C",0);
//        String exp_str = ExpressionUtil.buildStatement(rule);
//        System.out.println("解析的公式:"+ exp_str );
////
////        Expression compile = AviatorEvaluator.compile(exp_str);
////        System.out.println("解析结果:"+ compile.execute());
//
//    }
//}
